package com.lbssoft.gpsbd.service.impl;

import com.lbssoft.gpsbd.dao.PoiMapper;
import com.lbssoft.gpsbd.model.Poi;
import com.lbssoft.gpsbd.model.PoiPermission;
import com.lbssoft.gpsbd.model.Result;
import com.lbssoft.gpsbd.model.vo.UserVo;
import com.lbssoft.gpsbd.service.PoiService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by nczc on 2018/6/5.
 */
@Service
public class PoiServiceImpl implements PoiService {
    @Autowired
    public PoiMapper poiMapper;

    @Override
    public List<Poi> list(long userId) {
        return poiMapper.list(userId);
    }

    @Override
    public Result add(Poi poi) {
        UserVo user = (UserVo) SecurityUtils.getSubject().getPrincipal();
        Result result = new Result();
        poiMapper.add(poi);
        PoiPermission poiPermission = new PoiPermission();
        poiPermission.setUserId(user.getId());
        poiPermission.setPoiId(poi.getId());
        poiMapper.addUserPoi(poiPermission);
        result.setData(poi);
        return result;
    }

    @Override
    public void delete(int id) {
        poiMapper.delete(id);
    }

    @Override
    public void update(Poi poi) {
        poiMapper.update(poi);
    }
}
